package com.shudai.largescreen.service.impl;

import cn.hutool.core.date.DateTime;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.shudai.largescreen.mapper.DeptMapper;
import com.shudai.largescreen.pojo.User;
import com.shudai.largescreen.pojo.vo.*;
import com.shudai.largescreen.service.SalesmanService;
import com.shudai.largescreen.util.DateQuery;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
@Slf4j
public class SalesmanServiceImpl implements SalesmanService {

    private final DeptMapper deptMapper;

    @Override
    public BigDatasource getDeptDaily(String province, String region, String teamName, String startTime) {
        System.out.println("getDeptDaily: ");
        LocalDateTime todayEndTime = null;
        LocalDateTime todayStartTime = null;
        if (StringUtils.isEmpty(startTime)) {
            todayEndTime = DateQuery.getTodayEndTime(LocalDateTime.now().minusDays(1));
            todayStartTime = DateQuery.getTodayStartTime(LocalDateTime.now().minusDays(1));

        } else {
            todayEndTime = DateQuery.getTodayEndTime(startTime);
            todayStartTime = DateQuery.getTodayStartTime(startTime);
        }


        //查部门人数 部门id
        List<AllCityAmount> datasource = deptMapper.findDeptNumber(province, region, teamName);
        List<BigDatasource> amountList = new ArrayList<>();
        if (ObjectUtils.isNotEmpty(datasource)) {
            int totalNumber = 0;
            for (AllCityAmount allCityAmount : datasource) {
                totalNumber += Integer.parseInt(allCityAmount.getTotal());

                //查下单量
                String orderDaily = deptMapper.findOrderDaily(allCityAmount.getFinish(), todayStartTime, todayEndTime);

                //当日拜访量
                String visitDaily = deptMapper.findVisitDaily(allCityAmount.getFinish(), todayStartTime, todayEndTime);

                BigDatasource bigDatasource = new BigDatasource();
                bigDatasource.setTodayOrder(orderDaily);
                bigDatasource.setTodayOrderAvg(new BigDecimal(orderDaily).divide(new BigDecimal(allCityAmount.getTotal()), 2, RoundingMode.HALF_UP));
                bigDatasource.setTodayVisitAvg(new BigDecimal(visitDaily).divide(new BigDecimal(allCityAmount.getTotal()), 2, RoundingMode.HALF_UP));
                bigDatasource.setTodayVisit(visitDaily);
                amountList.add(bigDatasource);
            }
            BigDatasource bigDatasources = new BigDatasource();
            int totalOrder = 0;
            int todayVisit = 0;

            for (BigDatasource bigDatasource : amountList) {
                totalOrder += Integer.parseInt(bigDatasource.getTodayOrder());
                todayVisit += Integer.parseInt(bigDatasource.getTodayVisit());

            }
            bigDatasources.setTodayOrder(totalOrder + "");
            bigDatasources.setTodayVisit(todayVisit + "");
            bigDatasources.setTodayOrderAvg(new BigDecimal(totalOrder).divide(new BigDecimal(totalNumber), 2, RoundingMode.HALF_UP));
            bigDatasources.setTodayVisitAvg(new BigDecimal(todayVisit).divide(new BigDecimal(totalNumber), 2, RoundingMode.HALF_UP));

            return bigDatasources;
        }
        return null;
    }

    @Override
    public MiddleDatasource getDeptMoth(String province, String region, String teamName, String startTime) {
        LocalDateTime todayEndTime = null;
        LocalDateTime todayStartTime = null;
        if (StringUtils.isEmpty(startTime)) {
            todayEndTime = DateQuery.getTodayEndTime(LocalDateTime.now().minusDays(1));
            todayStartTime = DateQuery.getTodayStartTime(LocalDateTime.now().minusDays(1));

        } else {
            todayEndTime = DateQuery.getTodayEndTime(startTime);
            todayStartTime = DateQuery.getTodayStartTime(startTime);
        }

        //查部门人数 部门id
        List<AllCityAmount> datasource = deptMapper.findDeptNumber(province, region, teamName);
        List<MiddleDatasource> middleDatasources = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(datasource)) {
            int totalNumber = 0;
            for (AllCityAmount allCityAmount : datasource) {
                totalNumber += Integer.parseInt(allCityAmount.getTotal());

                //查当月订单
                String orderMoth = deptMapper.findOrderMoth(allCityAmount.getFinish(), todayStartTime, todayEndTime);
                //查当月拜访
                String visitMoth = deptMapper.findVisitMoth(allCityAmount.getFinish(), todayStartTime, todayEndTime);

                MiddleDatasource middleDatasource = new MiddleDatasource();
                middleDatasource.setMonthOrder(orderMoth);
                middleDatasource.setMonthVisit(visitMoth);
                middleDatasource.setPartNum(allCityAmount.getTotal());
                middleDatasources.add(middleDatasource);
            }

            MiddleDatasource bigDatasources = new MiddleDatasource();
            int totalOrder = 0;
            int todayVisit = 0;


            for (MiddleDatasource bigDatasource : middleDatasources) {
                totalOrder += Integer.parseInt(bigDatasource.getMonthOrder());
                todayVisit += Integer.parseInt(bigDatasource.getMonthVisit());

            }

            bigDatasources.setMonthOrder(totalOrder + "");
            bigDatasources.setMonthVisit(todayVisit + "");
            bigDatasources.setPartNum(totalNumber + "");
            return bigDatasources;

        }
        return null;
    }


    @Override
    public MonthOrder getMonthOrder(String province, String region, String teamName, String startTime) {

        //查询部门下的人
        List<ChartData> chartDataSalles = deptMapper.findSalles(province, region, teamName);
        if (CollectionUtils.isNotEmpty(chartDataSalles)) {
            List<Long> collect = chartDataSalles.stream().map(ChartData::getId).collect(Collectors.toList());

            LocalDate someStart = null;
            LocalDate someEnd = null;
            if (StringUtils.isEmpty(startTime)) {
                String mothNow = (DateTime.now() + "").split(" ")[0].split("-")[0] + (DateTime.now() + "").split(" ")[0].split("-")[1];
                //这月的
                someStart = DateQuery.getMothSomeStart(mothNow);
                someEnd = DateQuery.getMothSomeEnd(mothNow);

            }


            if (StringUtils.isNotEmpty(startTime) && !startTime.substring(4).equals("01")) {
                someStart = DateQuery.getMothSomeStart(startTime);
                someEnd = DateQuery.getMothSomeEnd(startTime);


            }
            if (StringUtils.isNotEmpty(startTime) && startTime.substring(4).equals("01")) {
                someStart = DateQuery.getMothSomeStart(startTime);
                someEnd = DateQuery.getMothSomeEnd(startTime);
            }

            //本周第一天
//        String weekStart = DateQuery.getMothStart();
//        String weekStart = "2022-05-10 00:00:00";

            //1.具有转换功能的对象
            DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

            //3.LocalDate发动，将字符串转换成  df格式的LocalDateTime对象，的功能
            LocalDateTime startLocalTime = LocalDateTime.parse(someStart + " 00:00:00", df);
            LocalDateTime endLocalTime = LocalDateTime.parse(someEnd + " 00:00:00", df);


            List<ChartDataData> deptMoth = deptMapper.findDeptMoth(collect, startLocalTime, endLocalTime);
            for (ChartData chartDataSalle : chartDataSalles) {
                chartDataSalle.setData2("50");
                chartDataSalle.setData1(0);
                for (ChartDataData chartDataData : deptMoth) {
                    if (chartDataSalle.getId().equals(chartDataData.getId())) {
                        chartDataSalle.setData1(chartDataData.getData1());
                    }
                }
            }

            String moth = (DateTime.now() + "").split(" ")[0].split("-")[1] + "月";

            MonthOrder monthOrder = new MonthOrder();

            monthOrder.setCurrentMonth(moth);
            monthOrder.setAreaName(teamName);
            monthOrder.setFinish(chartDataSalles.stream().mapToInt(ChartData::getData1).sum());
            monthOrder.setTotalQuest("10000");
            monthOrder.setChartData(chartDataSalles);
            return monthOrder;
        }
        return null;
    }


    @Override
    public MonthOrder getMonthVitit(String province, String region, String teamName, String startTime) {

        //查询部门下的人
        List<ChartData> chartDataSalles = deptMapper.findSalles(province, region, teamName);


        if (CollectionUtils.isNotEmpty(chartDataSalles)) {
            LocalDate someStart = null;
            LocalDate someEnd = null;
            if (StringUtils.isEmpty(startTime)) {
                String mothNow = (DateTime.now() + "").split(" ")[0].split("-")[0] + (DateTime.now() + "").split(" ")[0].split("-")[1];
                //这月的
                someStart = DateQuery.getMothSomeStart(mothNow);
                someEnd = DateQuery.getMothSomeEnd(mothNow);

            }


            if (StringUtils.isNotEmpty(startTime) && !startTime.substring(4).equals("01")) {
                someStart = DateQuery.getMothSomeStart(startTime);
                someEnd = DateQuery.getMothSomeEnd(startTime);


            }
            if (StringUtils.isNotEmpty(startTime) && startTime.substring(4).equals("01")) {
                someStart = DateQuery.getMothSomeStart(startTime);
                someEnd = DateQuery.getMothSomeEnd(startTime);
            }

            //本周第一天
//        String weekStart = DateQuery.getMothStart();
//        String weekStart = "2022-05-10 00:00:00";

            //1.具有转换功能的对象
            DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

            //3.LocalDate发动，将字符串转换成  df格式的LocalDateTime对象，的功能
            LocalDateTime startLocalTime = LocalDateTime.parse(someStart + " 00:00:00", df);
            LocalDateTime endLocalTime = LocalDateTime.parse(someEnd + " 00:00:00", df);


            List<Long> collect = chartDataSalles.stream().map(ChartData::getId).collect(Collectors.toList());
            List<ChartDataData> deptMoth = deptMapper.findVititMoth(collect, startLocalTime, endLocalTime);

            for (ChartData chartDataSalle : chartDataSalles) {
                chartDataSalle.setData2("500");
                chartDataSalle.setData1(0);
                for (ChartDataData chartDataData : deptMoth) {
                    if (chartDataSalle.getId().equals(chartDataData.getId())) {
                        chartDataSalle.setData1(chartDataData.getData1());
                    }
                }
            }
            String moth = (DateTime.now() + "").split(" ")[0].split("-")[1] + "月";
            MonthOrder monthOrder = new MonthOrder();

            monthOrder.setCurrentMonth(moth);
            monthOrder.setAreaName(teamName);
            monthOrder.setFinish(chartDataSalles.stream().mapToInt(ChartData::getData1).sum());
            monthOrder.setTotalQuest("10000");
            monthOrder.setChartData(chartDataSalles);
            return monthOrder;
        }
        return null;
    }


    @Override
    public MonthOrder getMonthReVitit(String province, String region, String teamName, String startTime) {

        //查询部门下的人
        List<ChartData> chartDataSalles = deptMapper.findSalles(province, region, teamName);
        if (CollectionUtils.isNotEmpty(chartDataSalles)) {

            LocalDate someStart = null;
            LocalDate someEnd = null;
            if (StringUtils.isEmpty(startTime)) {
                String mothNow = (DateTime.now() + "").split(" ")[0].split("-")[0] + (DateTime.now() + "").split(" ")[0].split("-")[1];
                //这月的
                someStart = DateQuery.getMothSomeStart(mothNow);
                someEnd = DateQuery.getMothSomeEnd(mothNow);

            }


            if (StringUtils.isNotEmpty(startTime) && !startTime.substring(4).equals("01")) {
                someStart = DateQuery.getMothSomeStart(startTime);
                someEnd = DateQuery.getMothSomeEnd(startTime);


            }
            if (StringUtils.isNotEmpty(startTime) && startTime.substring(4).equals("01")) {
                someStart = DateQuery.getMothSomeStart(startTime);
                someEnd = DateQuery.getMothSomeEnd(startTime);
            }

            //本周第一天
//        String weekStart = DateQuery.getMothStart();
//        String weekStart = "2022-05-10 00:00:00";

            //1.具有转换功能的对象
            DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

            //3.LocalDate发动，将字符串转换成  df格式的LocalDateTime对象，的功能
            LocalDateTime startLocalTime = LocalDateTime.parse(someStart + " 00:00:00", df);
            LocalDateTime endLocalTime = LocalDateTime.parse(someEnd + " 00:00:00", df);


            List<Long> collect = chartDataSalles.stream().map(ChartData::getId).collect(Collectors.toList());

            System.out.println("deptMoth: ");
            List<ChartDataData> deptMoth = deptMapper.findReVititMoth(collect, startLocalTime, endLocalTime);

            for (ChartData chartDataSalle : chartDataSalles) {
                chartDataSalle.setData2("500");
                chartDataSalle.setData1(0);
                for (ChartDataData chartDataData : deptMoth) {
                    if (chartDataSalle.getId().equals(chartDataData.getId())) {
                        chartDataSalle.setData1(chartDataData.getData1());
                    }
                }
            }

            String moth = (DateTime.now() + "").split(" ")[0].split("-")[1] + "月";
            MonthOrder monthOrder = new MonthOrder();

            monthOrder.setCurrentMonth(moth);
            monthOrder.setAreaName(teamName);
            monthOrder.setFinish(chartDataSalles.stream().mapToInt(ChartData::getData1).sum());
            monthOrder.setTotalQuest("10000");
            monthOrder.setChartData(chartDataSalles);
            return monthOrder;
        }
        return null;
    }


    @Override
    public List<DailyChartData> getDailyReport(String province, String region, String teamName, String startTime) {

        if (StringUtils.isEmpty(province) && StringUtils.isEmpty(region) && StringUtils.isEmpty(teamName)) {
            province = "广东省";
            region = "深圳市";
            teamName = "深圳东区";
        }


        //1.具有转换功能的对象
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        //获取当天开始时间

        //当天结束时间
        LocalDateTime startDay = null;
        LocalDateTime endDay = null;
        if (StringUtils.isEmpty(startTime)) {
            startDay = DateQuery.getTodayStartTime(LocalDateTime.now().minusDays(1));
            endDay = DateQuery.getTodayEndTime(LocalDateTime.now().minusDays(1));
        } else {
            startDay = DateQuery.getTodayStartTime(startTime);
            endDay = DateQuery.getTodayEndTime(startTime);
        }


        //查询部门下那些人
        List<DailyChartData> deptNumbers = deptMapper.findDeptNumbers(province, region, teamName);
        List<Long> collect = deptNumbers.stream().map(DailyChartData::getId).collect(Collectors.toList());
        //查询下单的人 日报
        List<DailyChartData> data = deptMapper.findOrderDailyNow(collect, startDay, endDay);
        //确认订单
        List<DailyChartData> chartData = deptMapper.findOrderTrue(collect, startDay, endDay);

        //拜访 user_r
        List<DailyChartData> dailyChartData = deptMapper.findVisitDailyNow(collect, startDay, endDay);
        //回访
        List<DailyChartData> dailyChartData1 = deptMapper.findVisitDailyRe(collect, startDay, endDay);

        List<DailyChartData> dailyChartDataList = new ArrayList<>();
        for (DailyChartData deptNumber : deptNumbers) {
            DailyChartData dailyChartData2 = new DailyChartData();
            //名字
            dailyChartData2.setSalesman(deptNumber.getSalesman());
            //战队名字
            dailyChartData2.setTeamName(province + "-" + region + "-" + teamName);
            dailyChartData2.setOrderNew("0");
            dailyChartData2.setOrderUnitNew("0");

            dailyChartData2.setOrderConfirm("0");
            dailyChartData2.setOrderConfirmMoney("0");
            dailyChartData2.setOrderConfirmUnit("0");
            dailyChartData2.setVisit("0");

            dailyChartData2.setRevisit("0");

            //订单
            if (CollectionUtils.isNotEmpty(data)) {
                for (DailyChartData datum : data) {
                    if (deptNumber.getId().equals(datum.getId())) {
                        dailyChartData2.setOrderNew(datum.getOrderNew() == null ? "0" : datum.getOrderNew());
                        dailyChartData2.setOrderUnitNew(datum.getOrderUnitNew() == null ? "0" : datum.getOrderUnitNew());
                    }
                }
            }
            //确认订单
            if (CollectionUtils.isNotEmpty(chartData)) {
                for (DailyChartData chartDatum : chartData) {
                    if (deptNumber.getId().equals(chartDatum.getId())) {
                        dailyChartData2.setOrderConfirm(chartDatum.getOrderConfirm() == null ? "0" : chartDatum.getOrderConfirm());
                        dailyChartData2.setOrderConfirmMoney(chartDatum.getOrderConfirmMoney() == null ? "0" : chartDatum.getOrderConfirmMoney());
                        dailyChartData2.setOrderConfirmUnit(chartDatum.getOrderConfirmUnit() == null ? "0" : chartDatum.getOrderConfirmUnit());
                    }
                }
            }
            if (CollectionUtils.isNotEmpty(dailyChartData)) {
                //拜访
                for (DailyChartData dailyChartDatum : dailyChartData) {
                    if (deptNumber.getId().equals(dailyChartDatum.getId())) {
                        dailyChartData2.setVisit(dailyChartDatum.getVisit() == null ? "0" : dailyChartDatum.getVisit());
                    }
                }
            }
            //回访
            if (CollectionUtils.isNotEmpty(dailyChartData1)) {
                for (DailyChartData dailyChartData3 : dailyChartData1) {
                    if (deptNumber.getId().equals(dailyChartData3.getId())) {
                        dailyChartData2.setRevisit(dailyChartData3.getRevisit() == null ? "0" : dailyChartData3.getRevisit());
                    }
                }
            }

            dailyChartDataList.add(dailyChartData2);
        }


        return dailyChartDataList;
    }


    @Override
    public Map<String, Object> getOrderAnalysis(String oEntryTime,
                                                String oCompare,
                                                String id) {

        System.out.println("oEntryTime: " + oCompare + " ::: " + oEntryTime + " ;" + id);
//        if (StringUtils.isEmpty(province) && StringUtils.isEmpty(region) && StringUtils.isEmpty(teamName)){
//            province = "广东省";
//            region = "深圳市";
//
//            teamName = "深圳东区";
//        }
        //根据 oEntryTime 来筛选业务员
        User user = null;
        if (StringUtils.isNotEmpty(id)) {
            user = deptMapper.selectById(id);
        }

        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");



        if (StringUtils.isEmpty(oEntryTime) && StringUtils.isEmpty(oCompare)) {
            //查询三个月入职人员
            LocalDateTime startMothLast2 = LocalDateTime.parse(DateQuery.getMothStartLast2(), df);
            LocalDateTime endMothLast2 = LocalDateTime.parse(DateQuery.getMothEnd(), df);
            //获取这个月创建的销售 总下单量
            List<ChartDataData> salesManMonth1 = deptMapper.findVisitMothSales2(startMothLast2, endMothLast2);
//            List<Long> ids = salesManMonth1.stream().map(ChartDataData::getId).collect(Collectors.toList());

            //这月 第一天和最后一天
            String mothStart = DateQuery.getMothStart();
//            String mothStart =  "2020-10-10 00:00:00";
            String mothEnd = DateQuery.getMothEnd();
//            String mothEnd = "2022-10-10 00:00:00";
            LocalDateTime startMoth = LocalDateTime.parse(mothStart, df);
            LocalDateTime endMoth = LocalDateTime.parse(mothEnd, df);

////            //获取这个月创建的销售 总下单量
//            List<ChartDataData> salesManMonth = deptMapper.findOrderEntryTwos1(ids, startMoth, endMoth);


//            Map<String, Map<String, Object>> mapMap = new HashMap<>();
//
//            mapMap.put("entryOne", getOrderSaless(startMoth, endMoth, salesManMonth, "入职一个月"));


            Map<String, Object> orderSalesLastMoth = getOrderSaless(startMoth, endMoth, salesManMonth1, "入职一个月");

            Map<String, Object> objectMap = new HashMap<>();
            objectMap.put("chartName", "入职三个月");
            objectMap.put("totalVisit", (Integer) orderSalesLastMoth.get("totalVisit"));
            objectMap.put("totalOrder", (Integer) orderSalesLastMoth.get("totalOrder"));
            objectMap.put("chartData", orderSalesLastMoth.get("chartData"));
            objectMap.put("listData", orderSalesLastMoth.get("listData"));

//            List< Map<String, Object>> list = new ArrayList<>();
//
//            list.add(objectMap);

            Map<String, Object> maps = new HashMap<>();
            maps.put("entryOne", objectMap);
            maps.put("salesman", orderSalesLastMoth.get("salesman"));
            maps.put("entryTime", (((salesManMonth1.get(0).getTime()).split(" ")[0].split("-")[1])) + "月");

            return maps;

        }

        if (oEntryTime.equals("1") && StringUtils.isEmpty(oCompare)) {
            //这月 第一天和最后一天
            String mothStart = DateQuery.getMothStart();
//            String mothStart =  "2020-10-10 00:00:00";
            String mothEnd = DateQuery.getMothEnd();
//            String mothEnd = "2022-10-10 00:00:00";
            LocalDateTime startMoth = LocalDateTime.parse(mothStart, df);
            LocalDateTime endMoth = LocalDateTime.parse(mothEnd, df);

            //这上月 第一天和最后一天
            String mothStartLast2 = DateQuery.getMothStartLast2();
            String mothEndLast2 = DateQuery.getMothEndLast2();
            LocalDateTime startMothLast2 = LocalDateTime.parse(mothStartLast2, df);
            LocalDateTime endMothLast2 = LocalDateTime.parse(mothEndLast2, df);

//            List<ChartDataData> visitMothSales2 = deptMapper.findVisitMothSales2(startMoth, endMoth);
            List<ChartDataData> visitMothSales2 = deptMapper.findVisitMothSales2(startMothLast2, endMoth);
            List<Long> idList = visitMothSales2.stream().map(ChartDataData::getId).collect(Collectors.toList());

            List<Long> ids = new ArrayList<>();
            if (StringUtils.isEmpty(id)) {
                ids = idList;
            } else {
                List<Long> collect = idList.stream().filter(x -> x.equals(Long.parseLong(id))).collect(Collectors.toList());
                if (CollectionUtils.isNotEmpty(collect)) {
                    ids = collect;
                } else {
                    Map<String, Object> maps = new HashMap<>();
                    Map<String, Object> objectMap = new HashMap<>();
                    maps.put("entryOne", objectMap);

                    if (user != null) {
                        maps.put("salesman", user.getNickname());
                        maps.put("entryTime", ((user.getCreatedAt() + "").split(" ")[0].split("-")[1]) + "月");
                    } else {
                        maps.put("salesman", "无");
                        maps.put("entryTime", ((DateTime.now() + "").split(" ")[0].split("-")[1]) + "月");
                    }


                    return maps;
                }

            }
////            //获取这个月创建的销售 总下单量
            List<ChartDataData> salesManMonth = deptMapper.findOrderEntryTwos2(ids, startMoth, endMoth);
//
//
//            Map<String, Map<String, Object>> mapMap = new HashMap<>();
//
//            mapMap.put("entryOne", getOrderSaless(startMoth, endMoth, salesManMonth, "入职一个月"));


            Map<String, Object> orderSalesLastMoth = getOrderSaless(startMoth, endMoth, salesManMonth, "入职一个月");

            Map<String, Object> objectMap = new HashMap<>();
            objectMap.put("chartName",((DateTime.now() + "").split(" ")[0].split("-")[1]) + "月");
            objectMap.put("totalVisit", (Integer) orderSalesLastMoth.get("totalVisit"));
            objectMap.put("totalOrder", (Integer) orderSalesLastMoth.get("totalOrder"));
            objectMap.put("chartData", orderSalesLastMoth.get("chartData"));
            objectMap.put("listData", orderSalesLastMoth.get("listData"));

//            List< Map<String, Object>> list = new ArrayList<>();
//
//            list.add(objectMap);

            Map<String, Object> maps = new HashMap<>();
            maps.put("entryOne", objectMap);
            if (user != null) {
                maps.put("salesman", user.getNickname());
                maps.put("entryTime", ((user.getCreatedAt() + "").split(" ")[0].split("-")[1]) + "月");
            } else {
                maps.put("salesman", orderSalesLastMoth.get("salesman"));
                maps.put("entryTime", ((visitMothSales2.get(0).getTime()).split(" ")[0].split("-")[1]) + "月");
            }

            return maps;
        }

        if (oEntryTime.equals("2") && StringUtils.isEmpty(oCompare)) {
            //这月 第一天和最后一天
            String mothStartLast = DateQuery.getMothStartLast();
            String mothEndLast = DateQuery.getMothEndLast();
            LocalDateTime startMothLast = LocalDateTime.parse(mothStartLast, df);
            LocalDateTime endMothLast = LocalDateTime.parse(mothEndLast, df);

//            String mothStart =  "2020-10-10 00:00:00";
//            String mothEnd = DateQuery.getMothEnd();
//            String mothEnd = "2022-10-10 00:00:00";

            //这月 第一天和最后一天
            String mothStart = DateQuery.getMothStart();
            String mothEnd = DateQuery.getMothEnd();
            LocalDateTime startMoth = LocalDateTime.parse(mothStart, df);
            LocalDateTime endMoth = LocalDateTime.parse(mothEnd, df);

            //这上月 第一天和最后一天
            String mothStartLast2 = DateQuery.getMothStartLast2();
            String mothEndLast2 = DateQuery.getMothEndLast2();
            LocalDateTime startMothLast2 = LocalDateTime.parse(mothStartLast2, df);
            LocalDateTime endMothLast2 = LocalDateTime.parse(mothEndLast2, df);

            //获取这个月创建的销售
//            List<ChartDataData> salesManMonth1 = deptMapper.findVisitMothSales2(startMothLast, endMothLast);
            List<ChartDataData> salesManMonth1 = deptMapper.findVisitMothSales2(startMothLast2, endMothLast);
            List<Long> idList = salesManMonth1.stream().map(ChartDataData::getId).collect(Collectors.toList());
            List<Long> ids = new ArrayList<>();
            if (StringUtils.isEmpty(id)) {
                ids = idList;
            } else {
                List<Long> collect = idList.stream().filter(x -> x.equals(Long.parseLong(id))).collect(Collectors.toList());
                if (CollectionUtils.isNotEmpty(collect)) {
                    ids = collect;
                } else {
                    Map<String, Object> maps = new HashMap<>();
                    Map<String, Object> objectMap = new HashMap<>();
                    maps.put("entryOne", objectMap);
                    if (user != null) {
                        maps.put("salesman", user.getNickname());
                        maps.put("entryTime", ((user.getCreatedAt() + "").split(" ")[0].split("-")[1]) + "月");
                    } else {
                        maps.put("salesman", "无");
                        maps.put("entryTime", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 1) + "月");
                    }

                    return maps;
                }

            }


            List<ChartDataData> salesManMonth = deptMapper.findOrderEntryTwos2(ids, startMothLast, endMothLast);


//            Map<String, Map<String, Object>> mapMap = new HashMap<>();
//            mapMap.put("entryOne", getOrderSaless(startMoth, endMoth, salesManMonth, "入职二个月"));

//            Map<String, Object> orderSalesLastMoth = getOrderSaless(startMoth, endMoth, salesManMonth, "入职二个月");
            Map<String, Object> orderSalesLastMoth = getOrderSaless(startMothLast, endMothLast, salesManMonth, "入职二个月");

            Map<String, Object> objectMap = new HashMap<>();
            objectMap.put("chartName", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 1) + "月");
            objectMap.put("totalVisit", (Integer) orderSalesLastMoth.get("totalVisit"));
            objectMap.put("totalOrder", (Integer) orderSalesLastMoth.get("totalOrder"));
            objectMap.put("chartData", orderSalesLastMoth.get("chartData"));
            objectMap.put("listData", orderSalesLastMoth.get("listData"));

            List<Map<String, Object>> list = new ArrayList<>();

            list.add(objectMap);

            Map<String, Object> maps = new HashMap<>();
            maps.put("entryOne", objectMap);

            if (user != null) {
                maps.put("salesman", user.getNickname());
                maps.put("entryTime", ((user.getCreatedAt() + "").split(" ")[0].split("-")[1]) + "月");
            } else {

                maps.put("salesman", orderSalesLastMoth.get("salesman"));
                maps.put("entryTime", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 1) + "月");
            }


            return maps;
        }


        if (oEntryTime.equals("2") && oCompare.equals("1")) {
           //这月 第一天和最后一天
            String mothStart = DateQuery.getMothStart();
            String mothEnd = DateQuery.getMothEnd();
            LocalDateTime startMoth = LocalDateTime.parse(mothStart, df);
            LocalDateTime endMoth = LocalDateTime.parse(mothEnd, df);

            //上月 第一天和最后一天
            String mothStartLast = DateQuery.getMothStartLast();
            String mothEndLast = DateQuery.getMothEndLast();
            LocalDateTime startMothLsat = LocalDateTime.parse(mothStartLast, df);
            LocalDateTime endMothLast = LocalDateTime.parse(mothEndLast, df);

            //这上月 第一天和最后一天
            //这上月 第一天和最后一天
            String mothStartLast2 = DateQuery.getMothStartLast2();
            String mothEndLast2 = DateQuery.getMothEndLast2();
            LocalDateTime startMothLast2 = LocalDateTime.parse(mothStartLast2, df);
            LocalDateTime endMothLast2 = LocalDateTime.parse(mothEndLast2, df);

            //获取这个月创建的销售
//            List<ChartDataData> salesManMonth1 = deptMapper.findVisitMothSales2(startMothLsat, endMothLast);
            List<ChartDataData> salesManMonth1 = deptMapper.findVisitMothSales2(startMothLast2, endMothLast);
            List<Long> idList = salesManMonth1.stream().map(ChartDataData::getId).collect(Collectors.toList());
            List<Long> ids = new ArrayList<>();
            if (StringUtils.isEmpty(id)) {
                ids = idList;
            } else {
                List<Long> collect = idList.stream().filter(x -> x.equals(Long.parseLong(id))).collect(Collectors.toList());
                if (CollectionUtils.isNotEmpty(collect)) {
                    ids = collect;
                } else {
                    Map<String, Object> maps = new HashMap<>();
                    Map<String, Object> objectMap = new HashMap<>();
                    maps.put("entryOne", objectMap);
                    if (user != null) {
                        maps.put("salesman", user.getNickname());
                        maps.put("entryTime", ((user.getCreatedAt() + "").split(" ")[0].split("-")[1]) + "月");
                    } else {
                        maps.put("salesman", "无");
                        maps.put("entryTime", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 1) + "月");
                    }


                    return maps;
                }

            }

            //获取这个月创建的销售
            List<ChartDataData> salesManMonthLast = deptMapper.findOrderEntryTwos2(ids, startMothLsat, endMothLast);

            Map<String, Object> orderSalesLastMoth = getOrderSaless(startMothLsat, endMothLast, salesManMonthLast, "入职二个月");

            Map<String, Object> objectMap = new HashMap<>();

            objectMap.put("chartName", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 1) + "月");
            objectMap.put("totalVisit", (Integer) orderSalesLastMoth.get("totalVisit"));
            objectMap.put("totalOrder", (Integer) orderSalesLastMoth.get("totalOrder"));
            objectMap.put("chartData", orderSalesLastMoth.get("chartData"));

//            Map<String,Map<String,Object>> mapMap = new HashMap<>();
//            mapMap.put("compareChart",orderSalesLastMoth);



            Map<String, Object> orderSalesMoth = getOrderSaless(startMoth, endMoth, salesManMonthLast, "入职一个月");
            orderSalesMoth.put("chartName", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])) + "月");

            Map<String, Object> objectMap1 = new HashMap<>();

            objectMap1.put("chartName", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])) + "月");
            objectMap1.put("totalVisit", (Integer) orderSalesMoth.get("totalVisit"));
            objectMap1.put("totalOrder", (Integer) orderSalesMoth.get("totalOrder"));
            objectMap1.put("chartData", orderSalesMoth.get("chartData"));


            BigDecimal OrderMoth = new BigDecimal(0);
            if ((Integer) orderSalesLastMoth.get("totalOrder") != 0) {
                OrderMoth = (new BigDecimal((Integer) orderSalesMoth.get("totalOrder")).
                        subtract(new BigDecimal((Integer) orderSalesLastMoth.get("totalOrder")))).
                        divide(new BigDecimal((Integer) orderSalesLastMoth.get("totalOrder")), 2, RoundingMode.HALF_UP);
            }

            BigDecimal VisitMoth = new BigDecimal(0);
            if ((Integer) orderSalesLastMoth.get("totalVisit") != 0) {
                VisitMoth = (new BigDecimal((Integer) orderSalesMoth.get("totalVisit")).
                        subtract(new BigDecimal((Integer) orderSalesLastMoth.get("totalVisit")))).
                        divide(new BigDecimal((Integer) orderSalesLastMoth.get("totalVisit")), 2, RoundingMode.HALF_UP);
            }

            List<Map<String, Object>> listss = new ArrayList<>();
            //11月-10月
            Map<String, Object> map = new HashMap<>();
            map.put("visit", VisitMoth);
            map.put("order", OrderMoth);
            map.put("visitName", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])) + "月比" + (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 1) + "月");
            map.put("orderName", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])) + "月比" + (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 1) + "月");
//            mapMap.put("compare",map);
            listss.add(map);


//            mapMap.put("compareChart",orderSalesMoth);
            List<Map<String, Object>> list = new ArrayList<>();

            list.add(objectMap);
            list.add(objectMap1);

            Map<String, Object> maps = new HashMap<>();
            maps.put("compareChart", list);
            maps.put("compare", listss);

            if (user != null) {
                maps.put("salesman", user.getNickname());
                maps.put("entryTime", ((user.getCreatedAt() + "").split(" ")[0].split("-")[1]) + "月");
            } else {

                maps.put("salesman", orderSalesLastMoth.get("salesman"));
                maps.put("entryTime", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 2) + "月");
            }


//           compareChart.add(mapMap);
//
//            //上月总单 这月总单
//            Integer totalOrderLast = (Integer)orderSalesLastMoth.get("totalOrder");
//            Integer totalOrder = (Integer)orderSalesMoth.get("totalOrder");
//            BigDecimal OrderMoth = new BigDecimal(0);
//            if (totalOrderLast!=0 ){
//                 OrderMoth = (new BigDecimal(totalOrder).subtract(new BigDecimal(totalOrderLast))).divide(new BigDecimal(totalOrderLast), 2, RoundingMode.HALF_UP);
//            }
//
//            //上月总拜访 这月总拜访
//            Integer totalVisitLast = (Integer)orderSalesLastMoth.get("totalVisit");
//            Integer totalVisitOrder = (Integer)orderSalesMoth.get("totalVisit");
//            BigDecimal VisitMoth = new BigDecimal(0);
//            if (totalVisitLast!=0){
//                 VisitMoth = (new BigDecimal(totalVisitOrder).subtract(new BigDecimal(totalVisitLast))).divide(new BigDecimal(totalVisitLast), 2, RoundingMode.HALF_UP);
//            }
//
//            Map<String,Object> map = new HashMap<>();
//            map.put("visit",VisitMoth);
//            map.put("order",OrderMoth);
//            map.put("visitName",(Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])-1) + "月比"+(Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])) + "月");
//            map.put("orderName",(Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])-1) + "月比"+(Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])) + "月");
////            mapMap.put("compare",map);

            return maps;
        }
//
        if (oEntryTime.equals("3") && StringUtils.isEmpty(oCompare)) {
            //这上月 第一天和最后一天
            String mothStartLast = DateQuery.getMothStartLast2();
            String mothEndLast = DateQuery.getMothEndLast2();
            LocalDateTime startMothLast = LocalDateTime.parse(mothStartLast, df);
            LocalDateTime endMothLast = LocalDateTime.parse(mothEndLast, df);

            //这月 第一天和最后一天
            String mothStart = DateQuery.getMothStart();
            String mothEnd = DateQuery.getMothEnd();
            LocalDateTime startMoth = LocalDateTime.parse(mothStart, df);
            LocalDateTime endMoth = LocalDateTime.parse(mothEnd, df);

//            List<ChartDataData> salesManMonth1 = deptMapper.findVisitMothSales2(startMothLast, endMothLast);
            List<ChartDataData> salesManMonth1 = deptMapper.findVisitMothSales2(startMothLast, endMothLast);
            List<Long> idList = salesManMonth1.stream().map(ChartDataData::getId).collect(Collectors.toList());
            List<Long> ids = new ArrayList<>();
            if (StringUtils.isEmpty(id)) {
                ids = idList;
            } else {
                List<Long> collect = idList.stream().filter(x -> x.equals(Long.parseLong(id))).collect(Collectors.toList());
                if (CollectionUtils.isNotEmpty(collect)) {
                    ids = collect;
                } else {
                    Map<String, Object> maps = new HashMap<>();
                    Map<String, Object> objectMap = new HashMap<>();
                    maps.put("entryOne", objectMap);
                    if (user != null) {
                        maps.put("salesman", user.getNickname());
                        maps.put("entryTime", ((user.getCreatedAt() + "").split(" ")[0].split("-")[1]) + "月");
                    } else {
                        maps.put("salesman", "无");
                        maps.put("entryTime", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 2) + "月");
                    }


                    return maps;
                }

            }

            System.out.println(" 获取这个月创建的销售 ");

            System.out.println("salesManMonth: " + salesManMonth1.toString());

            //获取这个月创建的销售
            List<ChartDataData> salesManMonthLast = deptMapper.findOrderEntryTwos2(ids, startMothLast, endMothLast);

//            Map<String, Object> orderSalesLastMoth = getOrderSaless(startMoth, endMoth, salesManMonthLast, "入职三个月");
            Map<String, Object> orderSalesLastMoth = getOrderSaless(startMothLast, endMothLast, salesManMonthLast, "入职三个月");


            System.out.println(JSON.toJSON(orderSalesLastMoth));

            Map<String, Object> objectMap = new HashMap<>();
            objectMap.put("chartName", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 2) + "月");
            objectMap.put("totalVisit", (Integer) orderSalesLastMoth.get("totalVisit"));
            objectMap.put("totalOrder", (Integer) orderSalesLastMoth.get("totalOrder"));
            objectMap.put("chartData", orderSalesLastMoth.get("chartData"));
            objectMap.put("listData", orderSalesLastMoth.get("listData"));

            List<Map<String, Object>> list = new ArrayList<>();

            list.add(objectMap);

            Map<String, Object> maps = new HashMap<>();
            maps.put("entryOne", objectMap);

            if (user != null) {
                maps.put("salesman", user.getNickname());
                maps.put("entryTime", ((user.getCreatedAt() + "").split(" ")[0].split("-")[1]) + "月");
            } else {
                maps.put("salesman", orderSalesLastMoth.get("salesman"));
                maps.put("entryTime", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 2) + "月");
            }


            return maps;
        }
        if (oEntryTime.equals("3") && oCompare.equals("1")) {
            //这上上月 第一天和最后一天
            String mothStartLast = DateQuery.getMothStartLast2();
            String mothEndLast = DateQuery.getMothEndLast2();
            LocalDateTime startMothLast = LocalDateTime.parse(mothStartLast, df);
            LocalDateTime endMothLast = LocalDateTime.parse(mothEndLast, df);

            //这月 第一天和最后一天
            String mothStart = DateQuery.getMothStart();
            String mothEnd = DateQuery.getMothEnd();
            LocalDateTime startMoth = LocalDateTime.parse(mothStart, df);
            LocalDateTime endMoth = LocalDateTime.parse(mothEnd, df);

//            List<ChartDataData> salesManMonth1 = deptMapper.findVisitMothSales2(startMothLast, endMothLast);
            List<ChartDataData> salesManMonth1 = deptMapper.findVisitMothSales2(startMothLast, endMothLast);
            List<Long> idList = salesManMonth1.stream().map(ChartDataData::getId).collect(Collectors.toList());
            List<Long> ids = new ArrayList<>();
            if (StringUtils.isEmpty(id)) {
                ids = idList;
            } else {
                List<Long> collect = idList.stream().filter(x -> x.equals(Long.parseLong(id))).collect(Collectors.toList());
                if (CollectionUtils.isNotEmpty(collect)) {
                    ids = collect;
                } else {
                    Map<String, Object> maps = new HashMap<>();
                    Map<String, Object> objectMap = new HashMap<>();
                    maps.put("entryOne", objectMap);
                    if (user != null) {
                        maps.put("salesman", user.getNickname());
                        maps.put("entryTime", ((user.getCreatedAt() + "").split(" ")[0].split("-")[1]) + "月");
                    } else {
                        maps.put("salesman", "无");
                        maps.put("entryTime", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 2) + "月");
                    }

                    return maps;
                }

            }

            //获取这个月创建的销售
            List<ChartDataData> salesManMonth = deptMapper.findOrderEntryTwos1(ids, startMothLast, endMothLast);

            Map<String, Map<String, Object>> mapMap = new HashMap<>();
            Map<String, Object> orderSalesMoth = getOrderSaless(startMoth, endMoth, salesManMonth, "入职三个月");


            orderSalesMoth.put("chartName", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])) + "月");
            mapMap.put("endMoth", orderSalesMoth);


            Map<String, Object> objectMap = new HashMap<>();

            objectMap.put("chartName", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])) + "月");
            objectMap.put("totalVisit", (Integer) orderSalesMoth.get("totalVisit"));
            objectMap.put("totalOrder", (Integer) orderSalesMoth.get("totalOrder"));
            objectMap.put("chartData", orderSalesMoth.get("chartData"));


            //上月 第一天和最后一天
            String mothStartLast1 = DateQuery.getMothStartLast();
            String mothEndLast1 = DateQuery.getMothEndLast();
            LocalDateTime startMothLsat1 = LocalDateTime.parse(mothStartLast1, df);
            LocalDateTime endMothLast1 = LocalDateTime.parse(mothEndLast1, df);

            Map<String, Object> orderSalesLastMoth = getOrderSaless(startMothLsat1, endMothLast1, salesManMonth, "入职二个月");
            orderSalesLastMoth.put("chartName", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 1) + "月");

            mapMap.put("mothEndLast", orderSalesLastMoth);

            Map<String, Object> objectMaps = new HashMap<>();

            objectMaps.put("chartName", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 1) + "月");
            if (ObjectUtils.isNotEmpty(orderSalesLastMoth)) {
                objectMaps.put("totalVisit", (int) orderSalesLastMoth.get("totalVisit"));
                objectMaps.put("totalOrder", (int) orderSalesLastMoth.get("totalOrder"));
                objectMaps.put("chartData", orderSalesLastMoth.get("chartData"));
            } else {
                objectMaps.put("totalVisit", 0);
                objectMaps.put("totalOrder", 0);
                objectMaps.put("chartData", 0);
            }


            BigDecimal OrderMoth = new BigDecimal(0);
            if ((int) orderSalesLastMoth.get("totalOrder") != 0) {
                OrderMoth = (new BigDecimal((int) orderSalesMoth.get("totalOrder")).
                        subtract(new BigDecimal((int) orderSalesLastMoth.get("totalOrder")))).
                        divide(new BigDecimal((int) orderSalesLastMoth.get("totalOrder")), 2, RoundingMode.HALF_UP);
            }

            BigDecimal VisitMoth = new BigDecimal(0);
            if ((int) orderSalesLastMoth.get("totalVisit") != 0) {
                VisitMoth = (new BigDecimal((int) orderSalesMoth.get("totalVisit")).
                        subtract(new BigDecimal((int) orderSalesLastMoth.get("totalVisit")))).
                        divide(new BigDecimal((int) orderSalesLastMoth.get("totalVisit")), 2, RoundingMode.HALF_UP);
            }

            List<Map<String, Object>> listss = new ArrayList<>();
            //11月-10月
            Map<String, Object> map = new HashMap<>();
            map.put("visit", VisitMoth);
            map.put("order", OrderMoth);
            map.put("visitName", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])) + "月比" + (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 1) + "月");
            map.put("orderName", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])) + "月比" + (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 1) + "月");
//            mapMap.put("compare",map);
            listss.add(map);


            List<Map<String, Object>> list = new ArrayList<>();

            list.add(objectMap);
            list.add(objectMaps);

            Map<String, Object> maps = new HashMap<>();
            maps.put("compareChart", list);
            maps.put("compare", listss);

            if (user != null) {
                maps.put("salesman", user.getNickname());
                maps.put("entryTime", ((user.getCreatedAt() + "").split(" ")[0].split("-")[1]) + "月");
            } else {

                maps.put("salesman", orderSalesLastMoth.get("salesman"));
                maps.put("entryTime", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 2) + "月");
            }


            return maps;
        }
        if (oEntryTime.equals("3") && oCompare.equals("3")) {
            //这上上月 第一天和最后一天
            String mothStartLast = DateQuery.getMothStartLast2();
            String mothEndLast = DateQuery.getMothEndLast2();
            LocalDateTime startMothLast = LocalDateTime.parse(mothStartLast, df);
            LocalDateTime endMothLast = LocalDateTime.parse(mothEndLast, df);

            //这月 第一天和最后一天
            String mothStart = DateQuery.getMothStart();
            String mothEnd = DateQuery.getMothEnd();
            LocalDateTime startMoth = LocalDateTime.parse(mothStart, df);
            LocalDateTime endMoth = LocalDateTime.parse(mothEnd, df);

//            List<ChartDataData> salesManMonth1 = deptMapper.findVisitMothSales2(startMothLast, endMothLast);
            List<ChartDataData> salesManMonth1 = deptMapper.findVisitMothSales2(startMothLast, endMothLast);
            List<Long> idList = salesManMonth1.stream().map(ChartDataData::getId).collect(Collectors.toList());
            List<Long> ids = new ArrayList<>();
            if (StringUtils.isEmpty(id)) {
                ids = idList;
            } else {
                List<Long> collect = idList.stream().filter(x -> x.equals(Long.parseLong(id))).collect(Collectors.toList());
                if (CollectionUtils.isNotEmpty(collect)) {
                    ids = collect;
                } else {
                    Map<String, Object> maps = new HashMap<>();
                    Map<String, Object> objectMap = new HashMap<>();
                    maps.put("entryOne", objectMap);
                    if (user != null) {
                        maps.put("salesman", user.getNickname());
                        maps.put("entryTime", ((user.getCreatedAt() + "").split(" ")[0].split("-")[1]) + "月");
                    } else {
                        maps.put("salesman", "无");
                        maps.put("entryTime", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 2) + "月");

                    }

                    return maps;
                }

            }

            //获取这个月创建的销售
            List<ChartDataData> salesManMonth = deptMapper.findOrderEntryTwos2(ids, startMothLast, endMothLast);
            System.out.println("当月销售： " + salesManMonth.toString());

//            Map<String,Map<String,Object>> mapMap = new HashMap<>();
            Map<String, Object> orderSalesMoth = getOrderSaless(startMoth, endMoth, salesManMonth, "入职三个月");
//            orderSalesMoth.put("chartName",(Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])) + "月");
//            mapMap.put("endMoth",orderSalesMoth);

//            if (orderSalesMoth == null){
//                Map<String, Object> maps = new HashMap<>();
//                Map<String, Object> objectMap = new HashMap<>();
//                maps.put("entryOne",objectMap);
//                maps.put("salesman",salesManMonth.get(0).getName());
//                maps.put("entryTime",(Integer.parseInt((DateTime.now()+"").split(" ")[0].split("-")[1])-2) + "月");
//
//                return maps;
//            }
//

            Map<String, Object> objectMap = new HashMap<>();

            objectMap.put("chartName", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])) + "月");
            objectMap.put("totalVisit", (Integer) orderSalesMoth.get("totalVisit"));
            objectMap.put("totalOrder", (Integer) orderSalesMoth.get("totalOrder"));
            objectMap.put("chartData", orderSalesMoth.get("chartData"));


            //上月 第一天和最后一天
            String mothStartLast1 = DateQuery.getMothStartLast();
            String mothEndLast1 = DateQuery.getMothEndLast();
            LocalDateTime startMothLsat1 = LocalDateTime.parse(mothStartLast1, df);
            LocalDateTime endMothLast1 = LocalDateTime.parse(mothEndLast1, df);


            Map<String, Object> orderSalesLastMoth = getOrderSaless(startMothLsat1, endMothLast1, salesManMonth, "入职二个月");
//            orderSalesLastMoth.put("chartName",(Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])-1) + "月");
//            mapMap.put("mothEndLast",orderSalesLastMoth);

            Map<String, Object> objectMaps = new HashMap<>();
            objectMaps.put("chartName", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 1) + "月");
            objectMaps.put("totalVisit", (Integer) orderSalesLastMoth.get("totalVisit"));
            objectMaps.put("totalOrder", (Integer) orderSalesLastMoth.get("totalOrder"));
            objectMaps.put("chartData", orderSalesLastMoth.get("chartData"));


            //上月总单 这月总单
            Integer totalOrderLast = (Integer) orderSalesLastMoth.get("totalOrder");
            Integer totalOrder = (Integer) orderSalesMoth.get("totalOrder");
            BigDecimal OrderMoth = new BigDecimal(0);
            if (totalOrderLast != 0) {
                OrderMoth = (new BigDecimal(totalOrder).subtract(new BigDecimal(totalOrderLast))).divide(new BigDecimal(totalOrderLast), 2, RoundingMode.HALF_UP);
            }

            //上月总拜访 这月总拜访
            Integer totalVisitLast = (Integer) orderSalesLastMoth.get("totalVisit");
            Integer totalVisitOrder = (Integer) orderSalesMoth.get("totalVisit");
            BigDecimal VisitMoth = new BigDecimal(0);
            if (totalVisitLast != 0) {
                VisitMoth = (new BigDecimal(totalVisitOrder).subtract(new BigDecimal(totalVisitLast))).divide(new BigDecimal(totalVisitLast), 2, RoundingMode.HALF_UP);
            }

            List<Map<String, Object>> listss = new ArrayList<>();
            //11月-10月
            Map<String, Object> map = new HashMap<>();
            map.put("visit", VisitMoth);
            map.put("order", OrderMoth);
            map.put("visitName", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])) + "月比" + (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 1) + "月");
            map.put("orderName", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])) + "月比" + (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 1) + "月");
//            mapMap.put("compare",map);
            listss.add(map);

            //上上月


            System.out.println(" ");
            Map<String, Object> orderSalesLastMothLast = getOrderSaless(startMothLast, endMothLast, salesManMonth, "入职二个月");
//            orderSalesLastMothLast.put("chartName",(Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])-2) + "月");
//            mapMap.put("mothEndLastLast",orderSalesLastMothLast);

            Map<String, Object> objectMapss = new HashMap<>();

            objectMapss.put("chartName", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 2) + "月");
            objectMapss.put("totalVisit", (Integer) orderSalesLastMothLast.get("totalVisit"));
            objectMapss.put("totalOrder", (Integer) orderSalesLastMothLast.get("totalOrder"));
            objectMapss.put("chartData", orderSalesLastMothLast.get("chartData"));


            //上月总单 这月总单
            Integer totalOrderLastLast = (Integer) orderSalesLastMothLast.get("totalOrder");

            BigDecimal OrderMothLast = new BigDecimal(0);
            if (totalOrderLastLast != 0) {
                OrderMothLast = (new BigDecimal(totalOrderLast).subtract(new BigDecimal(totalOrderLastLast))).divide(new BigDecimal(totalOrderLastLast), 2, RoundingMode.HALF_UP);
            }

            //上月总拜访 这月总拜访
            Integer totalVisitLastLast = (Integer) orderSalesLastMothLast.get("totalVisit");

            BigDecimal VisitMothLast = new BigDecimal(0);
            if (totalVisitLastLast != 0) {
                VisitMothLast = (new BigDecimal(totalVisitLast).subtract(new BigDecimal(totalVisitLastLast))).divide(new BigDecimal(totalVisitLastLast), 2, RoundingMode.HALF_UP);
            }
            //10月-9月
            Map<String, Object> mapLat = new HashMap<>();
            mapLat.put("visit", VisitMothLast);
            mapLat.put("order", OrderMothLast);
            mapLat.put("visitName", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 1) + "月比" + (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 2) + "月");
            mapLat.put("orderName", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 1) + "月比" + (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 2) + "月");
//            mapMap.put("compareLast",mapLat);
            listss.add(mapLat);


            //上月总单 这月总单
            //11月-9月
            Integer totalOrderLastLas = (Integer) orderSalesLastMothLast.get("totalOrder");
            Integer totalOrders = (Integer) orderSalesMoth.get("totalOrder");

            BigDecimal OrderMothLas = new BigDecimal(0);
            if (totalOrderLastLast != 0) {
                OrderMothLas = (new BigDecimal(totalOrders).subtract(new BigDecimal(totalOrderLastLas))).divide(new BigDecimal(totalOrderLastLas), 2, RoundingMode.HALF_UP);
            }

            //上月总拜访 这月总拜访
            Integer totalVisitLastLas = (Integer) orderSalesLastMothLast.get("totalVisit");
            Integer totalVisitOrders = (Integer) orderSalesMoth.get("totalVisit");

            BigDecimal VisitMothLasts = new BigDecimal(0);
            if (totalVisitLastLast != 0) {
                VisitMothLasts = (new BigDecimal(totalVisitOrders).subtract(new BigDecimal(totalVisitLastLas))).divide(new BigDecimal(totalVisitLastLas), 2, RoundingMode.HALF_UP);
            }

            Map<String, Object> mapLats = new HashMap<>();
            mapLats.put("visit", VisitMothLasts);
            mapLats.put("order", OrderMothLas);
            mapLats.put("visitName", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])) + "月比" + (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 2) + "月");
            mapLats.put("orderName", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])) + "月比" + (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 2) + "月");
//            mapMap.put("compareLast",mapLat);
            listss.add(mapLats);


            List<Map<String, Object>> list = new ArrayList<>();

            list.add(objectMap);
            list.add(objectMaps);
            list.add(objectMapss);
//            list.add(map);
//            list.add(mapLat);

            Map<String, Object> maps = new HashMap<>();
            maps.put("compareChart", list);
            maps.put("compare", listss);

            if (user != null) {
                maps.put("salesman", user.getNickname());
                maps.put("entryTime", ((user.getCreatedAt() + "").split(" ")[0].split("-")[1]) + "月");
            } else {

                maps.put("salesman", orderSalesLastMoth.get("salesman"));
                maps.put("entryTime", (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 2) + "月");
            }

            return maps;
        }

        return null;
    }


    @Override
    public List<ExcelSalesmanVo> findAll(String province,
                                         String region,
                                         String teamName) {


        //查询部门下的人 业务员名称 入职时间
        List<ChartData> chartDataSalles = deptMapper.findSalles(province, region, teamName);

        // 统计每个月数量
//        List<Long> collect = chartDataSalles.stream().map(ChartDataData::getId).collect(Collectors.toList());
//
//        for (Long aLong : collect) {
//            //查询拜访的
//            List<AllCityAmount> visit = deptMapper.findvisitAll(aLong);
//        }


        List<ExcelSalesmanVo> excelSalesmanVos = new ArrayList<>();

        for (ChartData chartDataSalle : chartDataSalles) {
            String[] s = chartDataSalle.getTime().split(" ")[0].split("-");
            String[] s1 = (DateTime.now() + "").split(" ")[0].split("-");
            int time = (Integer.parseInt(s1[0]) - Integer.parseInt(s[0])) * 12 + (Integer.parseInt(s1[1]) - Integer.parseInt(s[1]));

            if (time >= 3) {
                AllCityAmount orderMoths = new AllCityAmount();
                Integer vititMothNow = 0;
                for (int i = 0; i < 2; i++) {
                    ExcelSalesmanVo excelSalesmanVo = new ExcelSalesmanVo();

                    excelSalesmanVo.setUsername(chartDataSalle.getName());
                    //月拜访量
                    // 8 月 9月

                    if (i == 0) {
                        //8月
                        //拜访量
                        Integer vititMoth = deptMapper.findVititMoths(chartDataSalle.getId(), 2);
                        //下单量
                        AllCityAmount orderMoth = deptMapper.findOrderMoths(chartDataSalle.getId(), 2);

                        //9月
                        //拜访量
                        vititMothNow = deptMapper.findVititMoths(chartDataSalle.getId(), 1);
                        //下单量
                        orderMoths = deptMapper.findOrderMoths(chartDataSalle.getId(), 1);

                        // 对比与当前
                        excelSalesmanVo.setMothData((Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 2) + "月");
                        excelSalesmanVo.setMothNow((Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 1) + "月");

                        //当月下单
                        excelSalesmanVo.setVisitTotal(vititMothNow + "");
                        excelSalesmanVo.setOrderTotal(orderMoths.getFinish() + "");
                        excelSalesmanVo.setMothNowOrderTotal(orderMoths.getTotal() == null ? "0" : orderMoths.getTotal());

                        //对比月
                        excelSalesmanVo.setMothDataVisit(vititMoth + "");
                        excelSalesmanVo.setMothDataOrder(orderMoth.getFinish() + "");
                        excelSalesmanVo.setMothDataOrderTotal(orderMoth.getTotal() == null ? "0" : orderMoth.getTotal());


                        //增长比
//                        if (!StringUtils.isEmpty(excelSalesmanVo.getMothNowOrderTotal())){
                        if (!StringUtils.isEmpty(excelSalesmanVo.getMothNowOrderTotal()) && !excelSalesmanVo.getMothDataOrderTotal().equals("0.00") && !excelSalesmanVo.getMothDataOrderTotal().equals("0")) {
                            BigDecimal divide = (new BigDecimal(excelSalesmanVo.getMothNowOrderTotal()).subtract(new BigDecimal(excelSalesmanVo.getMothDataOrderTotal()))).divide(new BigDecimal(excelSalesmanVo.getMothDataOrderTotal()), 2, RoundingMode.HALF_UP);
                            excelSalesmanVo.setIncreaseRate(divide.multiply(new BigDecimal(100)) + "%");
                        } else {
                            excelSalesmanVo.setIncreaseRate(0 + "%");
                        }

                        excelSalesmanVo.setProvince(chartDataSalle.getProvince());
                        excelSalesmanVo.setTeamName(chartDataSalle.getProvince() + "-" + chartDataSalle.getCity() + "-" + chartDataSalle.getDeptName());
                        excelSalesmanVo.setEntryTime(chartDataSalle.getTime());

                        excelSalesmanVos.add(excelSalesmanVo);
                    }
                    //9月 10月
                    if (i == 1) {


//                        excelSalesmanVo.setMothNow((Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])-1)+"");

                        //10月
                        //拜访量
                        Integer vititMothNow1 = deptMapper.findVititMothNow(chartDataSalle.getId());
                        //下单量
                        AllCityAmount orderMoth = deptMapper.findOrderMothNow(chartDataSalle.getId());


                        //9月

                        // 对比与当前
                        excelSalesmanVo.setMothData((Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 1) + "月");
                        excelSalesmanVo.setMothNow((Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])) + "月");

                        //当月下单
                        excelSalesmanVo.setVisitTotal(vititMothNow1 + "");

                        if (orderMoth.getFinish() != null) {
                            excelSalesmanVo.setOrderTotal(orderMoth.getFinish() + "");
                        } else {
                            excelSalesmanVo.setOrderTotal(0 + "");
                        }

                        excelSalesmanVo.setMothNowOrderTotal(orderMoth.getTotal() == null ? "0" : orderMoth.getTotal());

                        //对比月
                        excelSalesmanVo.setMothDataVisit(vititMothNow + "");


                        if (ObjectUtils.isNotEmpty(orderMoths)) {
                            excelSalesmanVo.setMothDataOrder(((orderMoths.getFinish() == null ? 0 : orderMoths.getFinish()) + ""));
                            excelSalesmanVo.setMothDataOrderTotal(orderMoths.getTotal() == null ? "0" : orderMoths.getTotal());
                        }

                        //增长比
                        if (!StringUtils.isEmpty(excelSalesmanVo.getMothNowOrderTotal()) && !excelSalesmanVo.getMothDataOrderTotal().equals("0.00") && !excelSalesmanVo.getMothDataOrderTotal().equals("0")) {

                            BigDecimal divide = (new BigDecimal(excelSalesmanVo.getMothNowOrderTotal()).subtract(new BigDecimal(excelSalesmanVo.getMothDataOrderTotal()))).divide(new BigDecimal(excelSalesmanVo.getMothDataOrderTotal()), 2, RoundingMode.HALF_UP);
                            excelSalesmanVo.setIncreaseRate(divide.multiply(new BigDecimal(100)) + "%");
                        } else {
                            excelSalesmanVo.setIncreaseRate(0 + "%");
                        }
                        excelSalesmanVo.setProvince(chartDataSalle.getProvince());
                        excelSalesmanVo.setTeamName(chartDataSalle.getProvince() + "-" + chartDataSalle.getCity() + "-" + chartDataSalle.getDeptName());
                        excelSalesmanVo.setEntryTime(chartDataSalle.getTime());
                        excelSalesmanVos.add(excelSalesmanVo);

                    }
                }
            }

            if (time == 2 || time == 1) {
                Integer vititMothNow = 0;
                AllCityAmount orderMoths = new AllCityAmount();

                for (int i = 0; i < 2; i++) {

                    ExcelSalesmanVo excelSalesmanVo = new ExcelSalesmanVo();

                    excelSalesmanVo.setUsername(chartDataSalle.getName());
                    //月拜访量
                    // 8 月 9月

                    if (i == 0) {
                        //8月
                        //拜访量
//                        String vititMoth = deptMapper.findVititMoths(chartDataSalle.getId(),2);
                        //下单量
//                        AllCityAmount orderMoth = deptMapper.findOrderMoths(chartDataSalle.getId(), 2);


                        //9月
                        //拜访量
                        vititMothNow = deptMapper.findVititMoths(chartDataSalle.getId(), 1);
                        //下单量
                        orderMoths = deptMapper.findOrderMoths(chartDataSalle.getId(), 1);

                        // 对比与当前
                        excelSalesmanVo.setMothData((Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 2) + "月");
                        excelSalesmanVo.setMothNow((Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 1) + "月");

                        //当月下单
                        excelSalesmanVo.setVisitTotal(vititMothNow + "");
//                        excelSalesmanVo.setOrderTotal(orderMoths.getFinish()+"");

                        if (orderMoths.getFinish() != null) {
                            excelSalesmanVo.setOrderTotal(orderMoths.getFinish() + "");
                        } else {
                            excelSalesmanVo.setOrderTotal(0 + "");
                        }

//                        excelSalesmanVo.setMothNowOrderTotal(orderMoths.getTotal());
                        excelSalesmanVo.setMothNowOrderTotal(orderMoths.getTotal() == null ? "0" : orderMoths.getTotal());
                        //对比月
                        excelSalesmanVo.setMothDataVisit("-");
                        excelSalesmanVo.setMothDataOrder("-");
                        excelSalesmanVo.setMothDataOrderTotal("-");

                        //增长比
//                        BigDecimal divide = (new BigDecimal(excelSalesmanVo.getMothNowOrderTotal()).subtract(new BigDecimal(excelSalesmanVo.getMothDataOrder()))).divide(new BigDecimal(excelSalesmanVo.getMothDataOrder()), 2, RoundingMode.HALF_UP);
                        excelSalesmanVo.setIncreaseRate("-");

                        excelSalesmanVo.setProvince(chartDataSalle.getProvince());
                        excelSalesmanVo.setTeamName(chartDataSalle.getProvince() + "-" + chartDataSalle.getCity() + "-" + chartDataSalle.getDeptName());
                        excelSalesmanVo.setEntryTime(chartDataSalle.getTime());
                        excelSalesmanVos.add(excelSalesmanVo);

                    }
                    //9月 10月
                    if (i == 1) {


//                        excelSalesmanVo.setMothNow((Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])-1)+"");

                        //10月
                        //拜访量
                        Integer vititMothNow1 = deptMapper.findVititMothNow(chartDataSalle.getId());
                        //下单量
                        AllCityAmount orderMoth = deptMapper.findOrderMothNow(chartDataSalle.getId());


                        //9月

                        // 对比与当前
                        excelSalesmanVo.setMothData((Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 1) + "月");
                        excelSalesmanVo.setMothNow((Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])) + "月");

                        //当月下单
                        excelSalesmanVo.setVisitTotal(vititMothNow1 + "");

//                        excelSalesmanVo.setOrderTotal(orderMoth.getFinish()+"");
                        if (orderMoths.getFinish() != null) {
                            excelSalesmanVo.setOrderTotal(orderMoths.getFinish() + "");
                        } else {
                            excelSalesmanVo.setOrderTotal(0 + "");
                        }

//                        excelSalesmanVo.setMothNowOrderTotal(orderMoth.getTotal());
                        excelSalesmanVo.setMothNowOrderTotal(orderMoth.getTotal() == null ? "0" : orderMoths.getTotal());
                        //对比月
                        excelSalesmanVo.setMothDataVisit(vititMothNow + "");
                        if (ObjectUtils.isNotEmpty(orderMoths)) {
                            excelSalesmanVo.setMothDataOrder(((orderMoths.getFinish() == null ? 0 : orderMoths.getFinish()) + ""));
//                            excelSalesmanVo.setMothDataOrder(orderMoths.getFinish()+"");
                            excelSalesmanVo.setMothDataOrderTotal(orderMoths.getTotal() == null ? "0" : orderMoths.getTotal());
//
                        }

                        //增长比
//                        if (!StringUtils.isEmpty(excelSalesmanVo.getMothNowOrderTotal())){
                        if (!StringUtils.isEmpty(excelSalesmanVo.getMothNowOrderTotal()) && !excelSalesmanVo.getMothDataOrderTotal().equals("0.00") && !excelSalesmanVo.getMothDataOrderTotal().equals("0")) {
                            System.out.println((new BigDecimal(excelSalesmanVo.getMothNowOrderTotal()).subtract(new BigDecimal(excelSalesmanVo.getMothDataOrderTotal()))));
                            System.out.println("excelSalesmanVo: " + new BigDecimal(excelSalesmanVo.getMothNowOrderTotal()));
                            System.out.println("excelSalesmanVo: " + new BigDecimal(excelSalesmanVo.getMothDataOrderTotal()));

                            BigDecimal divide = (new BigDecimal(excelSalesmanVo.getMothNowOrderTotal()).subtract(new BigDecimal(excelSalesmanVo.getMothDataOrderTotal()))).divide(new BigDecimal(excelSalesmanVo.getMothDataOrderTotal()), 2, RoundingMode.HALF_UP);
                            excelSalesmanVo.setIncreaseRate(divide.multiply(new BigDecimal(100)) + "%");
                        } else {
                            excelSalesmanVo.setIncreaseRate(0 + "%");
                        }
                        excelSalesmanVo.setProvince(chartDataSalle.getProvince());
                        excelSalesmanVo.setTeamName(chartDataSalle.getProvince() + "-" + chartDataSalle.getCity() + "-" + chartDataSalle.getDeptName());
                        excelSalesmanVo.setEntryTime(chartDataSalle.getTime());
                        excelSalesmanVos.add(excelSalesmanVo);

                    }

                }
            }

            if (time < 1) {
                for (int i = 0; i < 1; i++) {

                    ExcelSalesmanVo excelSalesmanVo = new ExcelSalesmanVo();

                    excelSalesmanVo.setUsername(chartDataSalle.getName());

//                    excelSalesmanVo.setMothNow((Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])-1)+"");

                    //10月
                    //拜访量
                    Integer vititMothNow1 = deptMapper.findVititMothNow(chartDataSalle.getId());
                    //下单量
                    AllCityAmount orderMoth = deptMapper.findOrderMothNow(chartDataSalle.getId());


                    //9月

                    // 对比与当前
                    excelSalesmanVo.setMothData((Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1]) - 1) + "月");
                    excelSalesmanVo.setMothNow((Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])) + "月");

                    //当月下单
                    excelSalesmanVo.setVisitTotal(vititMothNow1 + "");
                    excelSalesmanVo.setOrderTotal(orderMoth.getFinish() + "");
//                    excelSalesmanVo.setMothNowOrderTotal(orderMoth.getTotal());
                    excelSalesmanVo.setMothNowOrderTotal(orderMoth.getTotal() == null ? "0" : orderMoth.getTotal());
                    //对比月
//                    excelSalesmanVo.setMothDataVisit(vititMothNow);
//                    if (ObjectUtils.isNotEmpty(orderMoths)){
//                        excelSalesmanVo.setMothDataOrder(orderMoths.getFinish()+"");
//                        excelSalesmanVo.setMothDataOrderTotal(orderMoths.getTotal());
//                    }
                    //对比月
                    excelSalesmanVo.setMothDataVisit("-");
                    excelSalesmanVo.setMothDataOrder("-");
                    excelSalesmanVo.setMothDataOrderTotal("-");

                    //增长比
//                    BigDecimal divide = (new BigDecimal(excelSalesmanVo.getMothNowOrderTotal()).subtract(new BigDecimal(excelSalesmanVo.getMothDataOrder()))).divide(new BigDecimal(excelSalesmanVo.getMothDataOrder()), 2, RoundingMode.HALF_UP);
                    excelSalesmanVo.setIncreaseRate("-");
                    excelSalesmanVo.setProvince(chartDataSalle.getProvince());
                    excelSalesmanVo.setTeamName(chartDataSalle.getProvince() + "-" + chartDataSalle.getCity() + "-" + chartDataSalle.getDeptName());
                    excelSalesmanVo.setEntryTime(chartDataSalle.getTime());
                    excelSalesmanVos.add(excelSalesmanVo);

                }
            }

        }

        // 入职当月拜访数
        return excelSalesmanVos;
    }


//    public Map<String,Object> getOrderSales(String province,
//                                            String region,
//                                            String teamName,
//                                            LocalDateTime startMoth,
//                                            LocalDateTime endMoth,
//                                            String name,
//                                            List<ChartDataData> orderMothDept,
//                                            List<ChartDataData> salesManMonth){
//
//
//
//           //总单量
//        System.out.println( " province+++: "+ province +"  : "  + region +" : "+ teamName);
//        int orderSum = 0;
//        if (CollectionUtils.isNotEmpty(orderMothDept)){
//            //总单量
//            orderSum = orderMothDept.stream().mapToInt(ChartDataData::getTotal).sum();
//        }
//
//
//        //第一周
//        int orderSum1 = orderMothDept.stream().filter(x -> x.getTimeLocal().isBefore(startMoth.plusDays(8))).mapToInt(ChartDataData::getTotal).sum();
//        //第二周
//        int orderSum2 = orderMothDept.stream().filter(x -> x.getTimeLocal().isAfter(startMoth.plusDays(8)) && x.getTimeLocal().isBefore(startMoth.plusDays(16))).mapToInt(ChartDataData::getTotal).sum();
//        //第三周
//        int orderSum3 = orderMothDept.stream().filter(x -> x.getTimeLocal().isAfter(startMoth.plusDays(16)) && x.getTimeLocal().isBefore(startMoth.plusDays(24))).mapToInt(ChartDataData::getTotal).sum();
//        //第四周
//        int orderSum4 = orderMothDept.stream().filter(x -> x.getTimeLocal().isAfter(startMoth.plusDays(24))).mapToInt(ChartDataData::getTotal).sum();
//
//        //总拜访
//        System.out.println("总拜访:  ");
//        List<ChartDataData> visitMothDept = deptMapper.findVisitMothDept(province, region, teamName, startMoth,endMoth);
//        int visitSum = 0;
//        if (CollectionUtils.isNotEmpty(visitMothDept)){
//            //总单量
//            visitSum = visitMothDept.stream().mapToInt(ChartDataData::getTotal).sum();
//        }
//
//
//        //第一周
//        int visitSum1 = visitMothDept.stream().filter(x -> x.getTimeLocal().isBefore(startMoth.plusDays(8))).mapToInt(ChartDataData::getTotal).sum();
//        //第二周
//        int visitSum2 = visitMothDept.stream().filter(x -> x.getTimeLocal().isAfter(startMoth.plusDays(8)) && x.getTimeLocal().isBefore(startMoth.plusDays(16))).mapToInt(ChartDataData::getTotal).sum();
//        //第三周
//        int visitSum3 = visitMothDept.stream().filter(x -> x.getTimeLocal().isAfter(startMoth.plusDays(16)) && x.getTimeLocal().isBefore(startMoth.plusDays(24))).mapToInt(ChartDataData::getTotal).sum();
//        //第四周
//        int visitSum4 = visitMothDept.stream().filter(x -> x.getTimeLocal().isAfter(startMoth.plusDays(24))).mapToInt(ChartDataData::getTotal).sum();
//
//
//        Map<String,Object> map = new HashMap<>();
//        map.put("chartName",name);
//        map.put("totalVisit",visitSum);
//        map.put("totalOrder",orderSum);
//
//        List<ChartData> chartDataList = new ArrayList<>();
//        ChartData chartData1 = new ChartData();
//        chartData1.setName("第一周");
//        chartData1.setData1(orderSum1);
//        chartData1.setData2(visitSum1+"");
//        chartDataList.add(chartData1);
//        ChartData chartData2 = new ChartData();
//        chartData2.setName("第二周");
//        chartData2.setData1(orderSum2);
//        chartData2.setData2(visitSum2+"");
//        chartDataList.add(chartData2);
//        ChartData chartData3 = new ChartData();
//        chartData3.setName("第三周");
//        chartData3.setData1(orderSum3);
//        chartData3.setData2(visitSum3+"");
//        chartDataList.add(chartData3);
//        ChartData chartData4 = new ChartData();
//        chartData4.setName("第四周");
//        chartData4.setData1(orderSum4);
//        chartData4.setData2(visitSum4+"");
//        chartDataList.add(chartData4);
//        map.put("chartData",chartDataList);
//
//         if (CollectionUtils.isNotEmpty(salesManMonth)){
//             System.out.println("salesManMonth1: "+salesManMonth.toString());
//            //这个月的总拜访
//            List<ChartDataData> visitMothSales = deptMapper.findVisitMothSales(salesManMonth.stream().map(ChartDataData::getId).collect(Collectors.toList()),startMoth,endMoth);
//            //总订单数成交金额
//            List<ChartDataData> orderMothSales = deptMapper.findOrderMothSales(salesManMonth.stream().map(ChartDataData::getId).collect(Collectors.toList()),startMoth,endMoth);
//            List<ListData> MothSaleList = new ArrayList<>();
//             for (ChartDataData chartDataData : salesManMonth) {
//                 ListData listData = new ListData();
//                 listData.setName(chartDataData.getName());
//                 listData.setVisitNumber("0");
////                 listData.setTeamName(region+"-"+teamName);
//                 listData.setTeamName(chartDataData.getCity()+"-"+chartDataData.getDeptName());
//                 if (CollectionUtils.isNotEmpty(visitMothSales)){
//                     for (ChartDataData visitMothSale : visitMothSales) {
//                         if (visitMothSale.getId().equals(chartDataData.getId())){
//                             listData.setVisitNumber(visitMothSale.getTotal()+"");
//                         }
//                     }
//                 }
//
//                 if (CollectionUtils.isNotEmpty(orderMothSales)){
//                     for (ChartDataData orderMothSale : orderMothSales) {
//                         if ( chartDataData.getId().equals(orderMothSale.getId())){
//                             listData.setOrderNumber(orderMothSale.getTotal());
//                             listData.setTotalMoney(orderMothSale.getAmount());
//                         }
//                     }
//                 }else {
//                     listData.setOrderNumber(0);
//                     listData.setTotalMoney(0);
//                 }
//
//                 MothSaleList.add(listData);
////                 List<List<ListData>> listList= new ArrayList<>();
////                 listList.add(MothSaleList);
//                 map.put("listData",MothSaleList);
//             }
//        }else {
////            ListData listData = new ListData();
//             List<ListData> MothSaleList = new ArrayList<>();
//
////             MothSaleList.add(listData);
//             map.put("listData",MothSaleList);
//        }
//
//
//        return map;
//    }


    public Map<String, Object> getOrderSaless(LocalDateTime startMoth,
                                              LocalDateTime endMoth,
                                              List<ChartDataData> salesManMonth,
                                              String name) {

        if (CollectionUtils.isNotEmpty(salesManMonth)) {

            System.out.println(salesManMonth.get(0).getId()+ " 传递的id "+ salesManMonth.get(0).getName());

            if (ObjectUtils.isNotEmpty(salesManMonth)) {
                System.out.println("salesManMonth1: " + salesManMonth.toString());
                List<Long> ids = salesManMonth.stream().map(ChartDataData::getId).collect(Collectors.toList());

                //这个月的总拜访
                List<ChartDataData> visitMothSales = deptMapper.findVisitMothSales3(ids, startMoth, endMoth);
                List<ChartDataData> visitMothSales1 = deptMapper.findVisitMothSales4(ids, startMoth, endMoth);



//                //查询部门下单量
//                List<ChartDataData> orderMothDept1 = deptMapper.findOrderMothDept1(ids, startMoth,endMoth);

                //总订单数成交金额
                List<ChartDataData> orderMothSales = deptMapper.findOrderMothSales(ids, startMoth, endMoth);

                List<ListData> MothSaleList = new ArrayList<>();
                int visitNumber = 0;
                int visitNumber1 = 0;

                for (ChartDataData chartDataData : salesManMonth) {
                    ListData listData = new ListData();
                    listData.setId(chartDataData.getId());
                    listData.setName(chartDataData.getName());
                    listData.setVisitNumber("0");
//                 listData.setTeamName(region+"-"+teamName);
                    listData.setTeamName(chartDataData.getCity() + "-" + chartDataData.getDeptName());
                    listData.setOrderNumber(0);
                    listData.setTotalMoney(0);

                    if (CollectionUtils.isNotEmpty(visitMothSales)) {
                        for (ChartDataData visitMothSale : visitMothSales) {
                            if (visitMothSale.getId().equals(chartDataData.getId())){
                                visitNumber = visitMothSale.getTotal();
                            }
                        }
                    }
                    if (CollectionUtils.isNotEmpty(visitMothSales1)){
                        for (ChartDataData dataData : visitMothSales1) {
                            if (dataData.getId().equals(chartDataData.getId())){
                                visitNumber1 = dataData.getTotal();
                            }
                        }
                    }

                    listData.setVisitNumber((visitNumber+visitNumber1) + "");


                    if (CollectionUtils.isNotEmpty(orderMothSales)) {
                        for (ChartDataData orderMothSale : orderMothSales) {
                            if (chartDataData.getId().equals(orderMothSale.getId())) {
                                listData.setOrderNumber(orderMothSale.getTotal());
                                listData.setTotalMoney(orderMothSale.getAmount());
                            }
                        }
                    }

                     visitNumber = 0;
                     visitNumber1 = 0;

                    MothSaleList.add(listData);
                }

                List<ListData> collect = MothSaleList.stream().sorted(Comparator.comparing(ListData::getOrderNumber).reversed()).collect(Collectors.toList());
                //查询部门下单量
                List<ChartDataData> orderMothDept = deptMapper.findOrderMothDept(collect.get(0).getId(), startMoth, endMoth);
//             //保持原有顺序-（LinkedHashMap按插曲顺序排序）
//            Map<String, List<Region>> modelList = value.stream().collect(Collectors.groupingBy(Region::getValue,
//            LinkedHashMap::new, Collectors.toCollection(ArrayList::new)));
//            LinkedHashMap<Long, ArrayList<ChartDataData>> collect1 = orderMothDept.stream().collect(Collectors.groupingBy(ChartDataData::getId, LinkedHashMap::new, Collectors.toCollection(ArrayList::new)));



                //拜访量
                //总单量
                int orderSum = 0;
                if (CollectionUtils.isNotEmpty(orderMothDept)) {
                    //总单量
                    orderSum = orderMothDept.stream().mapToInt(ChartDataData::getTotal).sum();
                    System.out.println("总单量 " + orderSum);
                }


                //第一周
                int orderSum1 = orderMothDept.stream().filter(x -> x.getTimeLocal().isBefore(startMoth.plusDays(8))).mapToInt(ChartDataData::getTotal).sum();
                //第二周
                int orderSum2 = orderMothDept.stream().filter(x -> x.getTimeLocal().isAfter(startMoth.plusDays(8)) && x.getTimeLocal().isBefore(startMoth.plusDays(16))).mapToInt(ChartDataData::getTotal).sum();
                //第三周
                int orderSum3 = orderMothDept.stream().filter(x -> x.getTimeLocal().isAfter(startMoth.plusDays(16)) && x.getTimeLocal().isBefore(startMoth.plusDays(24))).mapToInt(ChartDataData::getTotal).sum();
                //第四周
                int orderSum4 = orderMothDept.stream().filter(x -> x.getTimeLocal().isAfter(startMoth.plusDays(24))).mapToInt(ChartDataData::getTotal).sum();


                //总拜访
                System.out.println("总拜访:  ");
                List<ChartDataData> visitMothDept = deptMapper.findVisitMothDept(collect.get(0).getId(), startMoth, endMoth);
                List<ChartDataData> visitMothDept1 = deptMapper.findVisitMothDept1(collect.get(0).getId(), startMoth, endMoth);

                int visitSum = 0;
                if (CollectionUtils.isNotEmpty(visitMothDept) &&  CollectionUtils.isNotEmpty(visitMothDept1) ) {

                    //总单量
                    visitSum = visitMothDept.stream().mapToInt(ChartDataData::getTotal).sum() +
                            visitMothDept1.stream().mapToInt(ChartDataData::getTotal).sum();

                    System.out.println("总拜访1 " + visitSum);
                }

                if (CollectionUtils.isNotEmpty(visitMothDept) &&  CollectionUtils.isEmpty(visitMothDept1) ) {

                    //总单量
                    visitSum = visitMothDept.stream().mapToInt(ChartDataData::getTotal).sum() ;
                    System.out.println("总拜访2 " + visitSum);
                }
                if (CollectionUtils.isEmpty(visitMothDept) &&  CollectionUtils.isNotEmpty(visitMothDept1) ) {
                    //总单量
                    visitSum =  visitMothDept1.stream().mapToInt(ChartDataData::getTotal).sum();
                    System.out.println("总拜访3 " + visitSum);
                }

                System.out.println("总拜访 " + visitSum);

                //第一周
                int visitSum1 = visitMothDept.stream().filter(x -> x.getTimeLocal().isBefore(startMoth.plusDays(8))).mapToInt(ChartDataData::getTotal).sum();
                int visitSum11 = visitMothDept1.stream().filter(x -> x.getTimeLocal().isBefore(startMoth.plusDays(8))).mapToInt(ChartDataData::getTotal).sum();

                //第二周
                int visitSum2 = visitMothDept.stream().filter(x -> x.getTimeLocal().isAfter(startMoth.plusDays(8)) && x.getTimeLocal().isBefore(startMoth.plusDays(16))).mapToInt(ChartDataData::getTotal).sum();
                int visitSum22 = visitMothDept1.stream().filter(x -> x.getTimeLocal().isAfter(startMoth.plusDays(8)) && x.getTimeLocal().isBefore(startMoth.plusDays(16))).mapToInt(ChartDataData::getTotal).sum();

                //第三周
                int visitSum3 = visitMothDept.stream().filter(x -> x.getTimeLocal().isAfter(startMoth.plusDays(16)) && x.getTimeLocal().isBefore(startMoth.plusDays(24))).mapToInt(ChartDataData::getTotal).sum();
                int visitSum33 = visitMothDept1.stream().filter(x -> x.getTimeLocal().isAfter(startMoth.plusDays(16)) && x.getTimeLocal().isBefore(startMoth.plusDays(24))).mapToInt(ChartDataData::getTotal).sum();

                //第四周
                int visitSum4 = visitMothDept.stream().filter(x -> x.getTimeLocal().isAfter(startMoth.plusDays(24))).mapToInt(ChartDataData::getTotal).sum();
                int visitSum44 = visitMothDept1.stream().filter(x -> x.getTimeLocal().isAfter(startMoth.plusDays(24))).mapToInt(ChartDataData::getTotal).sum();


                Map<String, Object> map = new HashMap<>();
                map.put("chartName", name);

                map.put("totalVisit", visitSum);
                map.put("totalOrder", orderSum);
                System.out.println("map中的totalVisit "+map.get("totalVisit"));

                List<ChartData> chartDataList = new ArrayList<>();
                ChartData chartData1 = new ChartData();
                chartData1.setName("第一周");
                chartData1.setData1(orderSum1);
                chartData1.setData2((visitSum1 + visitSum11) + "");
                chartDataList.add(chartData1);
                ChartData chartData2 = new ChartData();
                chartData2.setName("第二周");
                chartData2.setData1(orderSum2);
                chartData2.setData2((visitSum2 + visitSum22) + "");
                chartDataList.add(chartData2);
                ChartData chartData3 = new ChartData();
                chartData3.setName("第三周");
                chartData3.setData1(orderSum3);
                chartData3.setData2((visitSum3 + visitSum33) + "");
                chartDataList.add(chartData3);
                ChartData chartData4 = new ChartData();
                chartData4.setName("第四周");
                chartData4.setData1(orderSum4);
                chartData4.setData2((visitSum4 + visitSum44) + "");
                chartDataList.add(chartData4);
                map.put("chartData", chartDataList);

                map.put("salesman", collect.get(0).getName());
                map.put("listData", collect);

                return map;
            }
//            else {
////            ListData listData = new ListData();
//                List<ListData> MothSaleList = new ArrayList<>();
//
////             MothSaleList.add(listData);
//                map.put("listData", MothSaleList);
//            }


//            return map;
        } else {

            Map<String, Object> map = new HashMap<>();
            map.put("chartName", name);
            map.put("totalVisit", 0);
            map.put("totalOrder", 0);

            List<ChartData> chartDataList = new ArrayList<>();
            ChartData chartData1 = new ChartData();
            chartData1.setName("第一周");
            chartData1.setData1(0);
            chartData1.setData2(0 + "");
            chartDataList.add(chartData1);
            ChartData chartData2 = new ChartData();
            chartData2.setName("第二周");
            chartData2.setData1(0);
            chartData2.setData2(0 + "");
            chartDataList.add(chartData2);
            ChartData chartData3 = new ChartData();
            chartData3.setName("第三周");
            chartData3.setData1(0);
            chartData3.setData2(0 + "");
            chartDataList.add(chartData3);
            ChartData chartData4 = new ChartData();
            chartData4.setName("第四周");
            chartData4.setData1(0);
            chartData4.setData2(0 + "");
            chartDataList.add(chartData4);
            map.put("chartData", chartDataList);

            map.put("salesman", "无");

            List<ListData> MothSaleList = new ArrayList<>();
            map.put("listData", MothSaleList);

            return map;
        }

        return null;
    }


}
